//
//  CZStatusToolBar.swift
//  微博
//
//  Created by 霸气的刘吉庆 on 16/4/20.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class CZStatusToolBar: UIView {
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        //添加控件,调用方法添加控件
       let retweetBtn = addChildButton("转发", imageName: "timeline_icon_retweet")
       let commentBtn =  addChildButton("评论", imageName: "timeline_icon_comment")
       let likeBtn = addChildButton("赞", imageName: "timeline_icon_unlike")
        
        //设置中间的2个竖线
        
        let sp1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let sp2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(sp1);addSubview(sp2)
        
        //设置约束
        
        retweetBtn.snp_makeConstraints { (make) -> Void in
         
            make.leading.top.bottom.equalTo(self)
            
            make.width.equalTo(commentBtn.snp_width)
        
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(likeBtn.snp_width)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentBtn.snp_trailing)
            make.top.trailing.bottom.equalTo(self)
            make.width.equalTo(retweetBtn.snp_width)
            
        }
        //设置竖线的约束
        sp1.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
            
        }
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        
    }
    
    
    private func addChildButton(title: String,imageName: String) -> UIButton {
    
        let button = UIButton(textColor: UIColor.darkGrayColor(), fontSize: 14)
        button.setTitle(title, forState: .Normal)
        //设置显示的照片
        button.setImage(UIImage(named: imageName), forState: .Normal)
    //设置不同状态下的背景颜色
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        //这里直接将按钮添加到bar上
        addSubview(button)
        
        return button
    
    }
    


}
